﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Estate_Autocomplete5.ascx.cs"
    Inherits="ZLDC.Estate.UserControl.Estate_Autocomplete5" %>

<!-- 找回我的盘源 查询出所有的楼盘 -->
<link href="../js/jquery.autocomplete/jquery.autocomplete.css" rel="stylesheet" type="text/css" />

<script src="../js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>

<script src="../js/jquery.autocomplete/jquery.autocomplete.min.js" type="text/javascript"></script>

<script src="../js/LexunJS.js" type="text/javascript"></script>

<script type="text/javascript">
    $(function() {

        $('#iEstateName').autocomplete("../Handler/HandlerIndex.ashx?act=all_estate_auto_list", {
            minChars: 2,
            extraParams: { usage: function() { return $('#use').val(); } },
            max: 100,
            //列表里的条目数
            width: 205,
            scroll: true,
            mustMatch: true,
            matchContains: false,
            //提示的宽度，溢出隐藏
            scrollHeight: 300,
            //提示的高度，溢出显示滚动条
            parse: function(data) {
                if (data == "" || data == undefined)
                    return false;

                return $.map(eval(data), function(row) {
                    return {
                        data: row,
                        value: row.id,
                        result: row.name
                    }
                });
            },
            formatItem: function(item) {
                return item.name;
            }
        });
        $("#iEstateName").result(function(event, data, formatted) {
            $("#dname").html("");
            $("#area").html("");
            if (data == null) {
                return;
            }
            var select = document.getElementById("dname");
            LexunJS.selectAddOption(select, data.cityname, data.cityid)
            document.getElementById("dname1").value = data.cityname;
            var sarea = document.getElementById("area");
            document.getElementById("area1").value = data.areaname;
            LexunJS.selectAddOption(sarea, data.areaname, data.areaid)
            document.getElementById("houseType").value = data.type;
            // 选中下拉中某行的事件
            loadBuild(data.id);
        });
    });
    //清楚输入框值
    function clearValue() {
        if (document.getElementById("iEstateName").value == "") {

            document.getElementById("buildName1").options.length = 0;
            document.getElementById("buildName2").options.length = 0;
            document.getElementById("buildName3").options.length = 0;
            document.getElementById("floor").value = "";
            document.getElementById("roomNo").value = "";
            document.getElementById("bname2").value = "";
            document.getElementById("bname3").value = "";
            
            
         }
     }
    // 清除输入框默认值
     function clearText() {
      
        document.getElementById("iEstateName").value = "";
        //清除select 的值
        document.getElementById("buildName1").options.length=0;
        document.getElementById("buildName2").options.length = 0;
        document.getElementById("buildName3").options.length = 0;
       

        document.getElementById("floor").value = "";
        document.getElementById("roomNo").value = "";
        document.getElementById("bname2").value = "";
        document.getElementById("bname3").value = "";

    }

    // 设置输入框默认值
    function setText() {
        if (document.getElementById("iEstateName").value == "") {
            document.getElementById("iEstateName").value = "楼盘名称、拼音均可";
        }
    }

    // 级联加载列表
    function loadBuild(id) {
        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerIndex.ashx',
            data: 'act=SelectNamesById&id=' + id,
            timeout: '10000',
            error: function() {
                alert("编缉失败！");
            }, success: function(json) {
                loadBuildCallBack(json);
            }
        });
    }

    // 加载城市列表回调
    function loadBuildCallBack(response) {
        var json = eval("(" + response + ")");
        var record = json.record;
        $("#buildName1").html("");
        $("#bid1").html("");

        var obj = document.getElementById("buildName1");
        LexunJS.selectAddOption(obj, "请选择", 0);
        if (record == null || record.length == 0)
            return;
        var recordLength = record.length;
        for (var i = 0; i < recordLength; i++) {
            var sName = record[i].name;
            var sValue = record[i].id;
            LexunJS.selectAddOption(obj, sName, sValue);
        }
    }
   
</script>

<input id="iEstateName" name="iEstateName" style="width: 28%" type="text" onclick="clearText();"
    class="textstyle1" onblur="setText();" onkeyup="clearValue();"  title="楼盘名称、拼音均可"  />